home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / if.test < prev    next >
Text File  |  1993-02-14  |  4KB  |  152 lines

  1. # Commands covered:  if
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991-1992 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /rel/cvsfiles/devo/tcl/tests/if.test,v 1.1.1.1 1992/11/07 04:46:56 zoo Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. test if-1.1 {taking proper branch} {
  21.     set a {}
  22.     if 0 {set a 1} else {set a 2}
  23.     set a
  24. } 2
  25. test if-1.2 {taking proper branch} {
  26.     set a {}
  27.     if 1 {set a 1} else {set a 2}
  28.     set a
  29. } 1
  30. test if-1.3 {taking proper branch} {
  31.     set a {}
  32.     if 1<2 {set a 1}
  33.     set a
  34. } 1
  35. test if-1.4 {taking proper branch} {
  36.     set a {}
  37.     if 1>2 {set a 1}
  38.     set a
  39. } {}
  40. test if-1.5 {taking proper branch} {
  41.     set a {}
  42.     if 0 {set a 1} else {}
  43.     set a
  44. } {}
  45. test if-1.5 {taking proper branch} {
  46.     set a {}
  47.     if 0 {set a 1} elseif 1 {set a 2} elseif 1 {set a 3} else {set a 4}
  48.     set a
  49. } {2}
  50. test if-1.6 {taking proper branch} {
  51.     set a {}
  52.     if 0 {set a 1} elseif 0 {set a 2} elseif 1 {set a 3} else {set a 4}
  53.     set a
  54. } {3}
  55. test if-1.7 {taking proper branch} {
  56.     set a {}
  57.     if 0 {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} else {set a 4}
  58.     set a
  59. } {4}
  60.  
  61.  
  62. test if-2.1 {optional then-else args} {
  63.     set a 44
  64.     if 0 then {set a 1} elseif 0 then {set a 3} else {set a 2}
  65.     set a
  66. } 2
  67. test if-2.2 {optional then-else args} {
  68.     set a 44
  69.     if 1 then {set a 1} else {set a 2}
  70.     set a
  71. } 1
  72. test if-2.3 {optional then-else args} {
  73.     set a 44
  74.     if 0 {set a 1} else {set a 2}
  75.     set a
  76. } 2
  77. test if-2.4 {optional then-else args} {
  78.     set a 44
  79.     if 1 {set a 1} else {set a 2}
  80.     set a
  81. } 1
  82. test if-2.5 {optional then-else args} {
  83.     set a 44
  84.     if 0 then {set a 1} {set a 2}
  85.     set a
  86. } 2
  87. test if-2.6 {optional then-else args} {
  88.     set a 44
  89.     if 1 then {set a 1} {set a 2}
  90.     set a
  91. } 1
  92. test if-2.7 {optional then-else args} {
  93.     set a 44
  94.     if 0 then {set a 1} else {set a 2}
  95.     set a
  96. } 2
  97. test if-2.8 {optional then-else args} {
  98.     set a 44
  99.     if 0 then {set a 1} elseif 0 {set a 2} elseif 0 {set a 3} {set a 4}
  100.     set a
  101. } 4
  102.  
  103. test if-3.1 {return value} {
  104.     if 1 then {set a 22; concat abc}
  105. } abc
  106. test if-3.2 {return value} {
  107.     if 0 then {set a 22; concat abc} elseif 1 {concat def} {concat ghi}
  108. } def
  109. test if-3.3 {return value} {
  110.     if 0 then {set a 22; concat abc} else {concat def}
  111. } def
  112. test if-3.4 {return value} {
  113.     if 0 then {set a 22; concat abc}
  114. } {}
  115. test if-3.5 {return value} {
  116.     if 0 then {set a 22; concat abc} elseif 0 {concat def}
  117. } {}
  118.  
  119. test if-4.1 {error conditions} {
  120.     list [catch {if} msg] $msg
  121. } {1 {wrong # args: no expression after "if" argument}}
  122. test if-4.2 {error conditions} {
  123.     list [catch {if {[error "error in condition"]}} msg] $msg
  124. } {1 {error in condition}}
  125. test if-4.3 {error conditions} {
  126.     list [catch {if 2} msg] $msg
  127. } {1 {wrong # args: no script following "2" argument}}
  128. test if-4.4 {error conditions} {
  129.     list [catch {if 2 then} msg] $msg
  130. } {1 {wrong # args: no script following "then" argument}}
  131. test if-4.5 {error conditions} {
  132.     list [catch {if 2 the} msg] $msg
  133. } {1 {invalid command name: "the"}}
  134. test if-4.6 {error conditions} {
  135.     list [catch {if 2 then {[error "error in then clause"]}} msg] $msg
  136. } {1 {error in then clause}}
  137. test if-4.7 {error conditions} {
  138.     list [catch {if 0 then foo elseif} msg] $msg
  139. } {1 {wrong # args: no expression after "elseif" argument}}
  140. test if-4.8 {error conditions} {
  141.     list [catch {if 0 then foo elsei} msg] $msg
  142. } {1 {invalid command name: "elsei"}}
  143. test if-4.9 {error conditions} {
  144.     list [catch {if 0 then foo elseif 0 bar else} msg] $msg
  145. } {1 {wrong # args: no script following "else" argument}}
  146. test if-4.10 {error conditions} {
  147.     list [catch {if 0 then foo elseif 0 bar els} msg] $msg
  148. } {1 {invalid command name: "els"}}
  149. test if-4.11 {error conditions} {
  150.     list [catch {if 0 then foo elseif 0 bar else {[error "error in else clause"]}} msg] $msg
  151. } {1 {error in else clause}}
  152.